﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Imaging;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace ImageCompress
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            ImageCodecInfo myImageCodecInfo = GetEncoderInfo(ImageFormat.Jpeg);

            //string source = @"D:\Temp\Vase1_01 - Default_BaseColor.png";
            //string destination = @"D:\Temp\Vase1_01 - Default_BaseColor";

            Example_SetTIFFCompression compress = new Example_SetTIFFCompression();

            //compress.Compress(source, destination + "-10.png", 10);
            //compress.Compress(source, destination + "-20.png", 20);
            //compress.Compress(source, destination + "-50.png", 50);
            //compress.Compress(source, destination + "-80.png", 80);
            //compress.Compress(source, destination + "-100.png", 100);

            //压缩比最大
            //compress.Compress(source, destination + "-10.jpg", 10);
            //compress.Compress(source, destination + "-20.jpg", 20);
            //compress.Compress(source, destination + "-50.jpg", 50);
            //compress.Compress(source, destination + "-80.jpg", 80);
            //compress.Compress(source, destination + "-100.jpg", 100);

            //compress.Compress(source, destination + "-10.tiff", 10);
            //compress.Compress(source, destination + "-20.tiff", 20);
            //compress.Compress(source, destination + "-50.tiff", 50);
            //compress.Compress(source, destination + "-80.tiff", 80);
            //compress.Compress(source, destination + "-100.tiff", 100);

            compress.Compress(@"D:\Temp\TestImageCompress\Chair_BaseColor.tif", @"D:\Temp\TestImageCompress\Chair_BaseColor.jpg", 50, myImageCodecInfo);
        }

        private static ImageCodecInfo GetEncoderInfo(ImageFormat format)
        {
            ImageCodecInfo[] codecs = ImageCodecInfo.GetImageDecoders();

            foreach (ImageCodecInfo codec in codecs)
            {
                if (codec.FormatID == format.Guid)
                {
                    return codec;
                }
            }

            return null;
        }
    }
}
